package Askgene::Database::Schema::Entry;

use strict;
use warnings;

use base qw/DBIx::Class/;
use Reaction::Class;
use Path::Class ();

use overload '""' => sub { shift->accession }, fallback => 1;

has accession => ( isa => 'NonEmptySimpleStr', is => 'rw', required => 1 );
has library =>
    ( isa => 'Askgene::Database::Schema::Library', is => 'rw', required => 1 );
has plate => ( isa => 'NonEmptySimpleStr', is => 'rw', required => 1 );
has created => ( isa => 'DateTime', is => 'ro' );

__PACKAGE__->load_components(qw/ UUIDColumns TimeStamp Core /);
__PACKAGE__->table('entries');
__PACKAGE__->add_columns(
    accession => {
        'data_type' => 'varchar',
        'size'      => '36',
    },
    project_name => {
        'data_type'   => 'varchar',
        'size'        => '50',
        'is_nullable' => '1',
    },
    lib_name => {
        'data_type'   => 'varchar',
        'size'        => '12',
        'is_nullable' => '1',
    },
    plate => {
        'data_type' => 'varchar',
        'size'      => '50',
    },
    created => {
        'data_type'     => 'timestamp',
        'set_on_create' => '1',
    },
);
__PACKAGE__->set_primary_key('accession');
__PACKAGE__->uuid_columns('accession');
__PACKAGE__->add_unique_constraint( [qw/project_name plate/] );

__PACKAGE__->might_have(
    'project' => 'Askgene::Database::Schema::Project',
    { 'foreign.name' => 'self.project_name' }
);
__PACKAGE__->might_have(
    'library' => 'Askgene::Database::Schema::Library',
    {   'foreign.project_name' => 'self.project_name',
        'foreign.name'         => 'self.lib_name'
    }
);

1;
